#!/usr/bin/python

from xml.dom.minidom import parse
import sys

def readcriteria(filename):
	"""
	Returns a dictionary for criterias read from custom file.
	"""
	dom = parse(filename)
	dict = {}
	for criteria in dom.childNodes:
		criteria_name = criteria.getAttribute('name')
		attributes = dict.get(criteria_name, [])
		for level in criteria.childNodes:
			attributes.append((level.getAttribute('weight'), level.getAttribute('caption')))
		dict[criteria_name] = attributes
	return dict

def main():
	"""
	Test function. Simple demonstrates reading criterias from a file.
	"""
	args = sys.argv[1:]
	if not args:
		sys.stderr.write("Usage: ./parser.py file \n")
		sys.exit(1)

	for file in args:
		criteria = readcriteria(file)
		print "--------" + file
		print criteria

if __name__ == "__main__":
	main()

